package com.joey.order.controller;

import com.cloud.api.client.ItemCart;
import com.cloud.api.client.ItemTest;
import com.joey.common.context.UserContext;
import com.joey.order.config.OrderProperties;
import com.joey.order.entity.GoodsCategory;
import com.joey.order.service.TestService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Joey
 * @Description:
 * @date:2024/6/9 23:55
 */
@RestController
@RequestMapping("/order")
@Slf4j
@RequiredArgsConstructor
public class orderController {

    @Autowired
    private TestService testService;
    @Autowired
    private ItemTest itemUser;
    @Autowired
    private ItemCart itCart;

//    @Autowired
    private final OrderProperties orderProperties;//    final

    @GetMapping("/service1")
    public List<GoodsCategory> send(){
        Long currentId = UserContext.getCurrentId();
        System.out.println("获取上下文UserInfo====>"+currentId);
        log.info("service1 to sql loading------");
        return testService.TestToSend();
    }

    @GetMapping("/service3")
    public String send3(){
        Long currentId = UserContext.getCurrentId();
        System.out.println("获取上下文UserInfo====>"+currentId);
        String s = itemUser.queryUser();
        log.info(s);
        return testService.TestToSend2();
    }
    @GetMapping("/service4")
    public String send4(){
        Long currentId = UserContext.getCurrentId();
        System.out.println("调用cart服务时,获取上下文UserInfo====>"+currentId);
        String s = itCart.queryCart();
        log.info(s);
        return testService.TestToSend2();
    }
    


    @GetMapping("/service2")
    public String send2(){
        log.info("service2-222");
        log.debug("动态配置数据maxNum:"+orderProperties.getMaxNum().toString());
        //order-service2
        return "动态配置数据maxNum:"+orderProperties.getMaxNum().toString();
    }
}
